feat(card-carousel): replace card_carousel.js with Rust/web_sys#39
Open
krishpranav wants to merge 1 commit into
Open
feat(card-carousel): replace card_carousel.js with Rust/web_sys#39krishpranav wants to merge 1 commit into
krishpranav wants to merge 1 commit into
Conversation
Migrates the vanilla JS carousel controller to a pure Rust module, eliminating the <script> tag and the JS file entirely. Two delegated listeners are registered once on `document` via a thread_local singleton (same pattern as use_input_otp): - click: walks up to CardCarouselNavButton, determines prev/next by DOM identity comparison against buttons[0], scrolls the track by one full clientWidth in the correct direction - scroll (capture phase): computes current slide index from scrollLeft / clientWidth, syncs aria-current on indicator dots and aria-disabled on prev/next nav buttons init() is called from CardCarouselTrack under #[cfg(target_arch = "wasm32")], so the hook activates automatically whenever the component mounts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
public/app_components/card_carousel.jswas a ~35-line vanilla JS file loadedvia a
<script type="module">tag in the demo. It handled nav button clicks andscroll-based indicator/button state updates through delegated listeners on
document.This PR replaces it entirely with a pure Rust module using
web_sys, followingthe same pattern established in #21 (lock_scroll.js) and #26 (otp.js).
What changed
app_crates/registry/src/hooks/use_card_carousel.rs— two delegatedevent listeners on
document, registered once via athread_local!singleton:CardCarouselNavButtonviaclosest(), identifies prev/next by DOM identity comparison againstbuttons[0], scrolls the track by one fullclientWidthscrollLeft / clientWidth, syncsaria-currenton indicator dots andaria-disabledon prev/next nav buttonsCardCarouselTrackto calluse_card_carousel::init()under#[cfg(target_arch = "wasm32")]— same pattern asuse_input_otp::init()in
InputOTPpublic/app_components/card_carousel.js<script>tag fromdemo_card_carousel.rsdemo_card_carousel.md) andtree.mdtoremove the
js:dependency entryValidation
Closes #27